<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>5*:实现时间的显示功能，
			要求能显示星期几，年月日，小时分钟秒,并能随着时间的变化而变化。。。</title>
<h1 id="date_time"></h1>//在body显示时间
		<script type="text/javascript">
			function getWeek(option) {
				var week = "日一二三四五六".charAt(option); //获取星期几
				return "星期" + week; //返回星期几
			}
			function showTime() {
				var dateTime = new Date();
				var year = dateTime.getFullYear(); //获取年份
				var month = dateTime.getMonth(); //获取月份
				month = month < 10 ? "0" + month : month; //月份小于10则前面加个"0"
				var date = dateTime.getDate(); //获取日
				date = date < 10 ? "0" + date : date;
				var hour = dateTime.getHours(); //获取小时
				hour = hour < 10 ? "0" + hour : hour;
				var minute = dateTime.getMinutes(); //获取分钟下·
				minute = minute < 10 ? "0" + minute : minute;
				var second = dateTime.getSeconds(); //获取秒
				second = second < 10 ? "0" + second : second;
				var day = dateTime.getDay()
				var week = getWeek(day);
				//年月日时分秒赋值给dateTime
				dateTime = year + "年" + month + "月" + date + "日" + "" + week + "" + hour + ":" + minute + ":" + second;
				document.getElementById("date_time").innerHTML = dateTime;
			}
			showTime(); //上来就显式  先动用这个方法一次
			setInterval("showTime()", 1000); //间隔多少毫秒执行一次
		</script>
	</head>
	<body>
	</body>
</html>
